package examples.contacts.model.validation

import javafx.scene.control.Control
import org.controlsfx.validation.ValidationResult
import org.controlsfx.validation.Validator

import java.time.LocalDate

/**
 * Created by Misty on 2015/6/6.
 */
class BirthdayValidator implements Validator<LocalDate>{
    @Override
    ValidationResult apply(Control control, LocalDate newValue) {
        if (newValue) {
            def now = LocalDate.now(CentralClock.clock)
            if (newValue.isAfter(now)) {
                return ValidationResult.fromError(control,"The birthday can't be set in the future")
            }
        }
        return null
    }
}
